
-module (shop).
-export ([total/1]).
-import (lists, [map/2, sum/1]).

cost(oranges)   -> 5;
cost(newspaper) -> 8;
cost(apples)    -> 2;
cost(pears)     -> 9;
cost(milk)      -> 7.

% V1
% total([{What, N} | T])  -> cost(What) * N + total(T);
% total([])               -> 0.

% V2
total(L) ->
    sum(map(fun({What, N}) -> cost(What) * N end, L)).

% V3
total(L) ->
    sum([cost(What) * N || {What, N} <- L]).


